<template>
  <div>
    <h2>当前求和为:{{ sum }}</h2>
    <button @click="changeSum">点我sum+1</button>
  </div>
</template>
<script setup lang="ts">
import { ref, watch } from "vue";

//数据
let sum = ref(0);

//方法
function changeSum() {
  sum.value += 1;
}

//监视(用的情况较多)
////<h1>情况一:监视[ref]定义的[基本类型]数据</h1>
//stopWatch是watch对停止动作取得名
//(newsum, oldsum)此为回调函数
const stopWatch = watch(sum, (newsum, oldsum) => {
  console.log("sum变化了", newsum, oldsum);
  if (newsum >= 10) {
    stopWatch();
  }
});
</script>
